import datetime
from model.car_number import CarNumber
from model.park_platform import ParkPlatform


class Result:
    def __init__(self) -> None:
        # 错误码
        self.error_code: str = ""
        # 是否成功
        self.success: bool = False
        # message
        self.message: str = ""

        # 停车平台
        self.platform: ParkPlatform = None

        # 车牌
        self.car_number: CarNumber = None
        # 入场时间
        self.enter_time: datetime.datetime = None
        # 费用
        self.price: float = 0

        # 停车场名称
        self.park_name: str = ""

        # 备注
        self.remark: str = ""

    def enter_time_str(self):
        if self.enter_time is None:
            return ""
        return self.enter_time.strftime("%Y-%m-%d %H:%M:%S")

    def stay_time_str(self):
        if self.enter_time is None:
            return ""
        stay_time = datetime.datetime.now() - self.enter_time
        return f"{stay_time.days}天 {stay_time.seconds//3600}小时 {(stay_time.seconds//60)%60}分钟"

    def price_str(self):
        return str(self.price) + "元"

    def __str__(self) -> str:
        if self.success:
            return f"""
查询平台: {self.platform.name}
查询车牌: {str(self.car_number)}
入场时间: {self.enter_time_str() }
停车时长: {self.stay_time_str() }
费用: {self.price_str()}
停车场名称: {self.park_name}
备注: {self.remark}
            """
        else:
            return f"""
查询平台: {self.platform.name}
查询车牌: {str(self.car_number)}
错误码: {self.error_code}
message: {self.message}
            """
